package com.itheima.tliasmanager.controller;

import com.itheima.tliasmanager.annotation.Log;
import com.itheima.tliasmanager.pojo.domain.Clazz;
import com.itheima.tliasmanager.pojo.Vo.PageResult;
import com.itheima.tliasmanager.pojo.Dto.QueryParam;
import com.itheima.tliasmanager.pojo.Vo.Result;
import com.itheima.tliasmanager.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @GetMapping("/list")
    public Result list(){
        log.info("查询全部班级信息");
        List<Clazz> clazz = clazzService.listAllClazz();
        return Result.success(clazz);
    }

    @GetMapping
    public Result page(QueryParam queryParam){
        log.info("分页查询班级列表，参数：{}",queryParam);
        PageResult<Clazz> pageResult = clazzService.page(queryParam);
        return Result.success(pageResult);
    }

    @Log
    @PostMapping
    public Result insertClazz(@RequestBody Clazz clazz)
    {
        log.info("---新增班级信息：{}",clazz);
        clazzService.addClazz(clazz);
        return Result.success();
    }

    @Log
    @PutMapping
    public Result updateClazz(@RequestBody Clazz clazz){
        log.info("更新班级信息，参数：{}",clazz);
        clazzService.updateClazz(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getclazzById(@PathVariable Integer id){
        log.info("查询班级信息，参数：{}",id);
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }

    @Log
    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable Integer id){
        log.info("删除班级信息，参数：{}",id);
        clazzService.removeById(id);
        return Result.success();
    }



}
